package com.hd.service.activiti.impl;

import com.hd.dao.BaseDao;
import com.hd.entity.activiti.TempStoageTask;
import com.hd.service.activiti.TempStoageTaskService;
import com.hd.util.result.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * 暂存任务
 */
@Service("tempStoageTaskService")
public class TempStoageTaskServiceImpl implements TempStoageTaskService {
    @Autowired
    private BaseDao<TempStoageTask,String>tempStoageTaskDao;
    @Override
    public Serializable save(TempStoageTask tempStoageTask) {
        tempStoageTask.setId(UUID.randomUUID().toString());
        return tempStoageTaskDao.save(tempStoageTask);
    }

    @Override
    public void selectDataGrid(PageInfo info) {
        List<Object> params=new ArrayList<Object>();
        Map<String,Object> condition=info.getCondition();
        String hql="from TempStoageTask where 1=1 and userid=?";
        params.add(condition.get("userid"));
        String countSql="select count(*)  " +hql;
        hql+=" order by createTime desc";
        List<TempStoageTask>vos=tempStoageTaskDao.findPage(hql, info.getNowpage(), info.getPagesize(), params);
        Long total=tempStoageTaskDao.getCountByList(countSql,params);
        info.setRows(vos);
        info.setTotal(Integer.parseInt(total.toString()));
    }



    @Override
    public void delete(String id) {
        String hql="delete from TempStoageTask where id=?";
        tempStoageTaskDao.execute(hql,id);
    }


    @Override
    public void delete(String businessKey, String objId) {
        String hql="delete from TempStoageTask where businessKey=? and objId=?";
        tempStoageTaskDao.execute(hql,businessKey,objId);
    }

    @Override
    public TempStoageTask get(String id) {
        return tempStoageTaskDao.get(TempStoageTask.class,id);
    }
}
